{extend name="../public/header" /}
{block name="body"}
<body>
	<div class="subject">
		<div class="layui-fluid">
			<div class="layui-row">
				<table class="layui-table" lay-size="sm">
					<thead>
					<tr>
						<th>昵称</th>
						<th>性别</th>
						<th>等级</th>
						<th width="100">操作</th>
					</tr>
					</thead>
					<tbody>
					{if(count($listRole)<1)}
					<tr>
						<td colspan="4" align="center">暂无相关数据</td>
					</tr>
					{else /}
					{volist name='listRole' id='vo' key='k'}
					<tr>
						<td>{$vo.uname}</td>
						<td>{if $vo.usex==1}男{else/}女{/if}</td>
						<td>{$vo.ulv}</td>
						<td>
							<a class="layui-btn layui-btn-xs layui-btn-danger ajax-del" data-url='{:url("del")}' data-field='id' data-value='{$vo.uid}'>删除</a>
							<a class="layui-btn layui-btn-xs ajax-opt" data-url='{:url("optRole")}' data-field='uid' data-value='{$vo.uid}'>进入</a>
						</td>
					</tr>
					{/volist}
					{/if}
					</tbody>
				</table>
				<a href='{:url("add")}' class="layui-btn layui-btn-fluid">创建</a>
			</div>
		</div>
	</div>
</body>
{/block}
{block name="script"}
<script>
layui.use(['jquery','form','laydate','upload','element'], function(){
	var $ = layui.jquery
	,laydate = layui.laydate
	,upload = layui.upload
	,element = layui.element
	,form = layui.form;

	$('.ajax-opt').on('click', function () {
		var obj = $(this);
		var url = obj.data('url');
		var field = obj.data('field');
		var value = obj.data('value');

		console.log('url', url);

		var map = {};
		map[field] = value;

		$.post(url, map, function (res) {
			if (res.code == undefined) {
				console.log('res为json字符串', res);
				res = JSON.parse(res);
			} else {
				console.log('res为json对象', res);
			}
			if (res.code == 1) {
				layer.msg(res.msg, {icon: 1, time: 1000}, function (index) {
					window.location.href = res.data.url;
				});
			} else {
				layer.msg(res.msg);
			}
		});
	});

	form.render();
});
</script>
{/block}
